package ClientController;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;

import Client.Client;
import ClientUI.ClientGUI;
import Protocol.user.Login_Q;
import Protocol.user.Login_R;

public class ListenerForServer implements Runnable {
	private    Client				client;
	private    ObjectInputStream 	in;
	private    HandlerForServer     handler;        
	
	public ListenerForServer(Client	c	, ObjectInputStream  input) {
		client = c;
		in = input;
		handler = new HandlerForServer(client);
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		Object       objectReceived = null;
		
		while (client.isOnline()) {
			try {
				objectReceived = in.readObject();
				System.out.println("Received Object from server : "+ objectReceived);
				
				handler.handle(objectReceived);
				
				
			} catch (IOException e) {
				// TODO Auto-generated catch block
				//client.getClientGui().displayServerFailure();
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
